using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Reflection;

using SypConst.Garbage;

namespace SypGui.ConnectionUC
{
    public partial class DirectStep2 : SypUCConnection
    {
        #region Init methods

        protected override void InitializeUC()
        {
            connMode = ConnectionMode.DIRECT_MODE;
        }

        public DirectStep2() : base() {}

        public DirectStep2(SetText outputMethod)
            : base(outputMethod){}

        protected override void InitializeRessources()
        {
            base.InitializeRessources();
            DirectStep2GroupBox.Text = GetRessources("WizardDirectSettings");
            LocalStep2RemotePathText.Text = GetRessources("WizardDirectRemotePath");
            LocalStep2TestButton.Text = GetRessources("WizardTestButton");
            LocalStep2BrowseButton.Text = GetRessources("OptionBrowseButton");
        }

        public override void Reset()
        {
            base.Reset();
            LocalStep2RemotePathText.Text = GetRessources("WizardDirectRemotePath");
        }

        #endregion

        public override void ProcessConfig()
        {
            string cmd = "Setconnection-site" + SypGarbage.COMMAND_SEPARATOR + SiteId + SypGarbage.COMMAND_SEPARATOR + (ushort)connMode + SypGarbage.COMMAND_SEPARATOR + "\"" + LocalStep2RemotePathText.Text + "\"";
            OutputMethod(cmd, Output.OUT);
            OutputMethod(cmd, Output.COMMAND);
            base.ProcessConfig();
        }


        #region accessors

        public string LocalRemotePath
        {
            get
            {
                return LocalStep2RemotePathText.Text;
            }
            set
            {
                LocalStep2RemotePathText.Text = value.ToString();
            }
        }

        #endregion


        #region events

        private void LocalStep2BrowseButton_Click(object sender, EventArgs e)
        {
            if (LocalStep2FolderDialog.ShowDialog() != DialogResult.OK)
            {
                LocalStep2RemotePathText.Text = GetRessources("WizardDirectRemotePath");
                Directory.SetCurrentDirectory(Application.StartupPath);
                return;
            }
            else
            {
                LocalStep2RemotePathText.Text = LocalStep2FolderDialog.SelectedPath;
                Directory.SetCurrentDirectory(Application.StartupPath);
            }

        }

        private void LocalStep2TestButton_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string testfolder = "hello";

            if (Directory.Exists(LocalStep2RemotePathText.Text))
            {
                try
                {
                    if (!Directory.Exists(LocalStep2RemotePathText.Text + "\\" + testfolder))
                        Directory.CreateDirectory(LocalStep2RemotePathText.Text + "\\" + testfolder);
                    Directory.Delete(LocalStep2RemotePathText.Text + "\\" + testfolder);

                    MessageBox.Show(GetRessources("DirectRemoteOK"));
                }
                catch (IOException)
                {
                    MessageBox.Show(GetRessources("DirectRemoteKO"));
                }
            }
            else
                MessageBox.Show(GetRessources("DirectRemoteKO"));
        }

        #endregion

       
    }
}
